﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraSplashScreen;
using System.Threading;
using System.IO;
using System.Xml;

namespace BACKOFFICE
{
    public partial class SplashScreen1 : SplashScreen
    {
        Thread StartupProcedures;
        public static SplashScreen1 _main;

        public SplashScreen1()
        {
            CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
            _main = this;  
        }

        #region Overrides

        public override void ProcessCommand(Enum cmd, object arg)
        {
            base.ProcessCommand(cmd, arg);
        }

        #endregion

        public enum SplashScreenCommand
        {
        }

        private void SplashScreen1_Load(object sender, EventArgs e)
        {
            StartupProcedures = new Thread(new ThreadStart(Startup1));
            StartupProcedures.Name = "STARTUP THREAD";
            StartupProcedures.Start();
        }

        void Startup1()
        {
            try
            {
                //try
                //{
                //    labelControl2.Text = "Getting Startup Information";
                //    Thread.Sleep(250);

                //    if (File.Exists(StaticProperties.FileLocation + StaticProperties.FileName))
                //    {
                //        XmlDocument xmldoc = new XmlDocument();
                //        XmlNodeList xmlnode;
                //        int i = 0;
                //        string str = null;
                //        FileStream fs = new FileStream("Startup.xml", FileMode.Open, FileAccess.Read);
                //        xmldoc.Load(fs);
                //        xmlnode = xmldoc.GetElementsByTagName("Startup");
                //        for (i = 0; i <= xmlnode.Count - 1; i++)
                //        {
                //            xmlnode[i].ChildNodes.Item(0).InnerText.Trim();
                //            str = xmlnode[i].ChildNodes.Item(0).InnerText.Trim();
                //            StaticProperties.SQLServerIP = (str);

                //            str = xmlnode[i].ChildNodes.Item(1).InnerText.Trim();
                //            StaticProperties.SQLServerPORT = (str);
                //        }

                //        StaticProperties.myConnectionString = StaticProperties.connectionstring();
                //    }
                //    else
                //    {
                //        SQLServerInfo addinfo = new SQLServerInfo();
                //        addinfo.ShowDialog();

                //        if (addinfo.DialogResult == System.Windows.Forms.DialogResult.OK)
                //        {
                //            //StaticProperties.StartupStuff.CreateStartupXMLFile(SQLServerInfo._main.lblserverIP.Text, SQLServerInfo._main.lblServerPORT.Text);

                StaticProperties.SQLServerIP = "192.168.1.13";// (SQLServerInfo._main.lblserverIP.Text);
                StaticProperties.SQLServerPORT = "1433";// (SQLServerInfo._main.lblServerPORT.Text);

                StaticProperties.myConnectionString = StaticProperties.connectionstring();
                //        }
                //    }
                //}
                //catch(Exception E)
                //{
                //    MessageBox.Show(E.Message);
                //}


                try
                {
                    Thread.Sleep(500);
                    if (DataTableClass.IsServerConnected())
                    {
                        //progressPanel1.Caption = "Loading Employee Data";
                        Thread.Sleep(125);
                        DataTableClass.LoadDataTable("EmployeeLogin", DataTableClass.EmployeeLogin);
                        Thread.Sleep(250);
                        DataTableClass.LoadDataTable("EmployeeInfo", DataTableClass.EmployeeInfo);
                        Thread.Sleep(250);
                        DataTableClass.LoadDataTable("EmployeeTimeSheet", DataTableClass.EmployeeTimeSheet);
                        Thread.Sleep(250);
                        DataTableClass.LoadDataTable("EmployeeSchedule", DataTableClass.EmployeeSchedule);
                        Thread.Sleep(250);
                        DataTableClass.LoadDataTable("JobTitles", DataTableClass.JobTitles);
                        Thread.Sleep(250);

                        //progressPanel1.Caption = "Loading Menu Items";
                        Thread.Sleep(125);
                        DataTableClass.LoadDataTable("MenuCategory", DataTableClass.MenuItemsCategory);
                        DataTableClass.LoadMenuCategoryDictionary();
                        Thread.Sleep(250);
                        DataTableClass.LoadDataTable("MenuItems", DataTableClass.MenuItems);
                        DataTableClass.LoadMenuItemsDictionary();
                        Thread.Sleep(250);
                        DataTableClass.LoadDataTable("ModificationList", DataTableClass.ModificationList);
                        //Thread.Sleep(250);


                        //progressPanel1.Caption = "Loading Receipt Data";
                        Thread.Sleep(125);
                        DataTableClass.LoadDataTable("Receipt", DataTableClass.Receipt);
                        Thread.Sleep(250);
                        DataTableClass.LoadDataTable("ReceiptData", DataTableClass.ReceiptData);
                        Thread.Sleep(250);
                        DataTableClass.LoadDataTable("PaymentTypes", DataTableClass.PaymentTypes);
                        Thread.Sleep(250);
                        DataTableClass.LoadDataTable("CCPaymentInfo", DataTableClass.CCPaymentInfo);
                        Thread.Sleep(250);
                    }

                    labelControl2.Text = "LOADING TABLE SEATING CHART";
                    StaticProperties.GetTableChartXML();
                    Thread.Sleep(125);

                    //StaticProperties.LoadPeripherals();

                    labelControl2.Text = "LOADING POS PRINTER SETTINGS";
                    //PrintingClass.PrintSetup();
                    Thread.Sleep(125);

                    Thread.Sleep(1000);
                    StaticProperties.StartingReceiptNo = 100;
                }
                catch
                {
                }
            }
            catch
            {
            }
            finally
            {
                this.Close();
            }
        }
    }
}